package handler

import (
	"github.com/name5566/leaf/gate"
	"server/game/arena"
	"server/msg/jsonData"
)

func EnterArena(args []interface{}) {
	m := args[0].(*jsonData.MsgEnterArenaReq)
	a := args[1].(gate.Agent)
	arenaObj := arena.NewArena(m.UserId)
	ret, err := arenaObj.EnterArena()
	if err != nil {
		a.WriteMsg(&jsonData.MsgRes{Ret: 1, Message: err.Error(), RequestId: m.RequestId})

	}
	a.WriteMsg(&jsonData.MsgRes{Ret: 0, Result: ret, RequestId: m.RequestId})
}
func BuyAddedChallenge(args []interface{}) {
	m := args[0].(*jsonData.MsgBuyBuyAddedChallengeReq)
	a := args[1].(gate.Agent)
	arenaObj := arena.NewArena(m.UserId)
	ret, err := arenaObj.BuyAddedChallenge(1)
	if err != nil {
		a.WriteMsg(&jsonData.MsgRes{Ret: 1, Message: err.Error(), RequestId: m.RequestId})
		return
	}
	a.WriteMsg(&jsonData.MsgRes{Ret: 0, Result: ret, RequestId: m.RequestId})
}
func Challenge(args []interface{}) {
	m := args[0].(*jsonData.MsgArenaChallengeReq)
	a := args[1].(gate.Agent)
	arenaObj := arena.NewArena(m.UserId)
	ret, err := arenaObj.Challenge(m.Pos, m.AtkedUid, m.BuyAddedChallengeNum, m.IsClearCdtime)
	if err != nil {
		a.WriteMsg(&jsonData.MsgRes{Ret: 1, Message: err.Error(), RequestId: m.RequestId})
		return
	}
	a.WriteMsg(&jsonData.MsgRes{Ret: jsonData.ErrCode(0), Result: ret, RequestId: m.RequestId})
}
func ArenaShop(args []interface{}) {
	m := args[0].(*jsonData.MsgArenaShopReq)
	arenaObj := arena.NewArena(m.UserId)
	ret, err := arenaObj.ArenaShop()
	a := args[1].(gate.Agent)
	if err != nil {
		a.WriteMsg(&jsonData.MsgRes{Ret: 1, Message: err.Error(), RequestId: m.RequestId})
		return
	}
	a.WriteMsg(&jsonData.MsgRes{Ret: jsonData.ErrCode(0), Result: ret, RequestId: m.RequestId})
}
func BuyArenaShop(args []interface{}) {
	m := args[0].(*jsonData.MsgBuyArenaShopReq)
	arenaObj := arena.NewArena(m.UserId)
	ret, err := arenaObj.BuyArenaShop(m.ItemId)
	a := args[1].(gate.Agent)
	if err != nil {
		a.WriteMsg(&jsonData.MsgRes{Ret: 1, Message: err.Error(), RequestId: m.RequestId})
		return
	}
	a.WriteMsg(&jsonData.MsgRes{Ret: jsonData.ErrCode(0), Result: ret, RequestId: m.RequestId})
}
func GetArenaInfo(args []interface{}) {
	m := args[0].(*jsonData.MsgArenaPaiHangReq)
	arenaObj := arena.NewArena(m.UserId)
	ret, err := arenaObj.GetInfo()
	a := args[1].(gate.Agent)
	if err != nil {
		a.WriteMsg(&jsonData.MsgRes{Ret: 1, Message: err.Error(), RequestId: m.RequestId})
		return
	}
	a.WriteMsg(&jsonData.MsgRes{Ret: jsonData.ErrCode(0), Result: ret, RequestId: m.RequestId})
}
